import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import bit.dao.BoardDAO;
import bit.dao.BoardDTO;


public class JsonList extends HttpServlet {
	protected void service(HttpServletRequest req, HttpServletResponse res) 
			throws ServletException, IOException {
		System.out.println("ajax");
		res.setContentType("text/html; charset=euc-kr");
		PrintWriter out = res.getWriter();
		
		BoardDAO dao = new BoardDAO();
		List<BoardDTO> list = dao.boardList();
		//java --> JSON API
		JSONObject obj = new JSONObject();

		JSONArray arr = new JSONArray();
		
		for(BoardDTO dto : list){
			obj.put("b", dto);
			arr.add(obj);
		}
		
		String json = arr.toString();
		out.println(json);
	}
}
